//
//  WLLWelcomeViewController.swift
//  WLLWeibo
//
//  Created by 王乐乐 on 16/8/12.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit
import SDWebImage

class WLLWelcomeViewController: UIViewController {

    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        //更改头像的顶部约束
        self.headImageView.snp_updateConstraints { (make) in
            make.top.equalTo(self.view).offset(100)
        }
        
        //设置动画
        UIView.animateWithDuration(2, delay: 1, usingSpringWithDamping: 0.7, initialSpringVelocity: 0, options: [], animations: { 
              //强制刷新UI(如果你使用的是约束 就需要这么干)
            self.view.layoutIfNeeded()
            }) { (_) in
                UIView.animateWithDuration(0.25, animations: { 
                    self.messageLabel.alpha = 1
                    }, completion: { (_) in
                         // 发送通知告知appdelegate 切换根控制器
                        NSNotificationCenter.defaultCenter().postNotificationName(WBSWITCHROOTVCNOTIFICATION, object: nil)
                })
        }
        
    
    }
    
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        setupUI()

    }
     //MARK: - 设置视图
  private  func setupUI()  {
       //添加控件
    view.addSubview(bgImageView)
    view.addSubview(headImageView)
        view.addSubview(messageLabel)
    //添加约束
    bgImageView.snp_makeConstraints { (make) in
        make.edges.equalTo(view).offset(UIEdgeInsetsZero)
    }
    headImageView.snp_makeConstraints { (make) in
        make.size.equalTo(CGSize(width: 90, height: 90))
        make.centerX.equalTo(view)
        make.top.equalTo(view).offset(400)
    }
    messageLabel.snp_makeConstraints { (make) in
        make.centerX.equalTo(view)
        make.top.equalTo(headImageView.snp_bottom).offset(16)
    }
    
    }
    
 //MARK: - 懒加载控件
     /// 背景图
  
   private  lazy var bgImageView :UIImageView = UIImageView(imageName:  "ad_background")
        /// 头像
    private lazy var headImageView : UIImageView = {
        let img = UIImageView()
     img.ll_setImageWithString(WLLUserAccountViewModel.shareTool.userAccount?.avatar_large, placeholderImageName: "avatar_default_big")
        img.layer.cornerRadius = 45
        img.layer.masksToBounds = true
        return img
    }()
     /// 欢迎回来
    private lazy var messageLabel :UILabel = {
        let label = UILabel ()
        label.font = UIFont.systemFontOfSize(18)
        label.textAlignment = .Center
        label.text = "欢迎回来"
        label.textColor = UIColor.darkGrayColor()
        label.alpha = 0
        return label
    }()
}
